<?php
/**
 * 单例模式
 * This file is part of pattern.
 * Author: tangzhou
 * Date: 2016/8/26
 * Time: 14:48
 * File: Sing.php
 */

class Sgin
{
    private static $instance = null;

    public $page;

    /**
     * 防止在外部实例化
     * Sgin constructor.
     */
    private function __construct()
    {

    }

    /**
     * 防止在外部clone
     */
    private function __clone()
    {

    }

    static public function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new Sgin();
        }

        return self::$instance;
    }
}

$s1 = Sgin::getInstance();
$s1->page = 20;

$s2 = Sgin::getInstance();
$s2->page = 26;

echo $s1->page.'----'.$s2->page;